﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CaseReview.Model;
using CaseReview.SQLServerDAL;
using CaseReview.Utility;

public partial class Reviewer_default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if(!IsPostBack) {
        //    BindData();
        //}
        BindData();
    }

    private void BindData() {
        string alias = Config.Alias;
        Dictionary<string, int> temp = (Dictionary<string,int>)Application["Reviewer"];
        int id = temp[alias];
        IList<CaseInfo> caseInfos =  BusinessLogic.GetInstance().GetTotalCaseByReviewer(id);
        for (int i = 0; i < caseInfos.Count; i++) {
            if (caseInfos[i].Status == 2)
            {
                caseInfos.Remove(caseInfos[i]);
                i = -1;
            }         
        }
        GridView1.DataSource = caseInfos;
        GridView1.DataKeyNames = new string[] { "CaseId" };
        GridView1.DataBind();

    }

    public static DataTable ExecuteDt(String Sqlstr)
    {
        String ConnStr = GetSqlConnection();
        using (SqlConnection conn = new SqlConnection(ConnStr))
        {
            SqlDataAdapter da = new SqlDataAdapter(Sqlstr, conn);
            DataTable dt = new DataTable(); conn.Open();
            da.Fill(dt);
            conn.Close();
            return dt;
        }
    }

    public static string GetSqlConnection()
    {
        ConnectionStringSettingsCollection connectionStringSettingsCollection =
            System.Web.Configuration.WebConfigurationManager.ConnectionStrings as ConnectionStringSettingsCollection;
        ConnectionStringSettings connectionStringSettings = connectionStringSettingsCollection["dbLocalConnectionString"];
        return connectionStringSettings.ConnectionString;
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) {
        GridView1.PageIndex = e.NewPageIndex;
        BindData();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //if (((LinkButton)e.Row.FindControl("LinkButton")) != null)
        //{
        //    LinkButton linkButton = (LinkButton)e.Row.FindControl("LinkButton");
        //    linkButton.Text = "Review";
        //}

        if (e.Row.RowIndex > -1) {
            string url = "showDetails.aspx?id=" + GridView1.DataKeys[e.Row.RowIndex].Value;
            e.Row.Cells[0].Text = @"<a href='" + url + "' target='_blank'>Reviewer</a>";
        }
        //if (e.Row.RowIndex > -1) {
        //    e.Row.Cells[0].Text = "Reviewer";
        //    string id = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
        //    e.Row.Cells[0].Attributes.Add("onclick", "var   st=window.showModalDialog( 'showDetails.aspx?val= '+ document.all());document.all( 'TextBox1 ').value=st;return   st; ");
        //}
    }

    //protected string ShowDetails(string id) {
    //    return "javascript: window.showModalDialog('" + 
    //     this.Page.ResolveUrl("showDetails.aspx?id=" + id) +
    //     "');";
    //}


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {

    }
}